<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .active{
            color: red;
        }
    </style>
</head>
<body>
    <div id="app">
        <ul>
            <!-- item:表示数组的每一项数据 -->
            <!-- index:表示数组的下标 -->
            <li v-for="(item,index) in movies" v-on:click="changeColor(item,index)" :class="{'active':item.flag}">{{item.name}}</li>
        </ul>
    </div>

    <script src="./vue.js"></script>
    <script>
        let app=new Vue({
            el:"#app",
            data:{
                movies:[
                    {name:"流浪地球",flag:false},
                    {name:"封神",flag:false},
                    {name:"人在囧途",flag:false},
                    {name:"泰囧",flag:false},
                ]

            },
            methods:{
                changeColor(item,index){
                    // 先全部把所有对象里面的flag值改为false
                    this.movies.forEach(element => {
                        element.flag=false
                    });

                    // 当前点击的电影对象的flag改为true
                    item.flag=!item.flag;
                }
            }
        })
    </script>
    
</body>
</html>